<template>
  <div style="height:100%">
    <Title title="访客数据统计" @click-more='handleClickMore'>
    </Title>
    <AccPie :echartData='echartData'>
      <div>
        <div>全校访客：{{sum}}人</div>
        <div v-for="(item, index) in echartData" :key="index">{{item.name}}：{{item.value}}人</div>
      </div>
    </AccPie>
  </div>
</template>

<script>
import { visitorCensus } from '@/views/children/antiepidemic/js/statisticalAnalysis'
import Vue from 'vue'
import { USER_INFO } from '@/store/mutation-types'
import Title from '../Title'
import AccPie from '../common/AccPie'

export default {
  // eslint-disable-next-line vue/no-unused-components
  components: { Title, AccPie },
  data () {
    return {
      currentCheck: '学生',
      echartData: [],
      sum: 0
    }
  },
  watch: {
    currentCheck: {
      handler () {
        this.getData()
      },
      immediate: true
    }
  },
  methods: {
    handleClickMore () {
      this.$router.push({ path: '/antiepidemic/visitorInfo' })
    },
    getData () {
      visitorCensus({
        tenantNo: Vue.ls.get(USER_INFO).tenantNo
      }).then(res => {
        const { data } = res
        this.sum = data.reduce((prev, cur) => {
          prev += cur.value
          return prev
        }, 0)
        console.log('da', data)
        this.echartData = data
      })
    }
  }
}
</script>

<style>

</style>
